//package com.ev;
///**
// * @author : CJH
// * @version 创建时间：2021年7月28日 下午2:00:04
// */
//
//import com.ev.entity.SummaryTable;
//import com.vividsolutions.jts.geom.*;
//import net.sf.json.JSONObject;
//import org.geotools.data.FeatureWriter;
//import org.geotools.data.Transaction;
//import org.geotools.data.shapefile.ShapefileDataStore;
//import org.geotools.data.shapefile.ShapefileDataStoreFactory;
//import org.geotools.data.simple.SimpleFeatureIterator;
//import org.geotools.data.simple.SimpleFeatureSource;
//import org.geotools.feature.simple.SimpleFeatureBuilder;
//import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
//import org.geotools.geojson.feature.FeatureJSON;
//import org.geotools.geometry.jts.JTSFactoryFinder;
//import org.geotools.referencing.crs.DefaultGeographicCRS;
//import org.opengis.feature.simple.SimpleFeature;
//import org.opengis.feature.simple.SimpleFeatureType;
//import org.opengis.referencing.crs.CoordinateReferenceSystem;
//
//import java.io.File;
//import java.io.Serializable;
//import java.io.StringWriter;
//import java.nio.charset.Charset;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//public class ChangeShp2 {
//    public static void main(String[] args) throws Exception {
//        read();
//    }
//
//    public static void read() throws Exception {
//        try {
//
//            File file = new File("C:\\Users\\55072\\Desktop\\新建文件夹\\汇总表.shp");
//            Map<String, Serializable> params = new HashMap<>();
//            params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
//
//            ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory().createDataStore(params);
//
//            // ds.setCharset(Charset.forName("UTF-8"));
//            SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
//            tb.setCRS(DefaultGeographicCRS.WGS84);
//            tb.setName("shapefile");
//            // add attributes in order
//            tb.add("the_geom", Point.class);
//            // <- 15 chars width for name field
//
//            String[] array = new String[]{"YEAR", "外业核查内容", "地块编号", "经度", "纬度", "DLMC", "DLDM", "是否变化", "GD", "YBD"
//                    , "EMC", "EDM", "照片文件路径", "林分结构", "优势树草种", "乔木郁闭度", "灌草盖度", "林下综合盖度", "综合盖度"
//                    , "坡度", "坡向", "株距", "行距", "冠幅", "生长周期", "梯田设计标准", "梯田类型", "田面宽度", "边坎类型", "梯田质量"
//                    , "损毁程度", "开垦利用方式", "所处地貌类型区", "所在区域", "对应的项目部位", "水土流失治理度", "项目所处的建设阶段"
//                    , "扰动方式", "QDLX", "QDDM", "BZ", "核查矢量编号", "检查", "TDLYDM_SL", "EDM_SL", "QD202153"};
//
//            for (String s : array) {
//                tb.length(100).add(s, String.class);
//            }
//            SimpleFeatureType type = tb.buildFeatureType();
//            ds.createSchema(type);
//            ds.setCharset(Charset.forName("GBK"));
//
//
//            FeatureWriter<SimpleFeatureType, SimpleFeature> featureWriter = ds
//                    .getFeatureWriter(Transaction.AUTO_COMMIT);
//
//
////// 设置编码
////            Charset charset = Charset.forName("GBK");
////            store.setCharset(charset);
////            SimpleFeatureSource sfSource = store.getFeatureSource();
////            SimpleFeatureIterator sfIter = sfSource.getFeatures().features();
////            File shapeFile1 = new File(shpPath1);
////            ShapefileDataStore store1 = new ShapefileDataStore(shapeFile1.toURI().toURL());
////            // 设置编码
////
////            store1.setCharset(charset);
////            SimpleFeatureSource sfSource1 = store1.getFeatureSource();
////            // SimpleFeatureIterator sfIter1 = sfSource1.getFeatures().features();
////            Object[] objects = sfSource1.getFeatures().toArray();
////            // 从ShapeFile文件中遍历每一个Feature，然后将Feature转为GeoJSON字符串
//
//
//            int cout = 0;
//            for (int num = 0; num < 5; num++) {
////                SimpleFeature feature = (SimpleFeature) sfIter.next();
//                // Feature转GeoJSON
////                FeatureJSON fjson = new FeatureJSON();
////                StringWriter writer = new StringWriter();
////                fjson.writeFeature(feature, writer);
////                String sjson = writer.toString();
////                JSONObject object = JSONObject.fromObject(sjson);
////                JSONObject properties = object.getJSONObject("properties");
////                JSONObject geometry = object.getJSONObject("geometry");
////
////                MultiLineString geom = (MultiLineString) feature.getAttribute("the_geom");
////                String typeObject = geometry.getString("type").toUpperCase();
////                List<JSONObject> startGeometries = new ArrayList<JSONObject>();
////                List<JSONObject> endGeometries = new ArrayList<JSONObject>();
////
////                for (Object feature1 : objects) {
////
////                    SimpleFeature feature2 = (SimpleFeature) feature1;
////                    Geometry geom1 = (Geometry) feature2.getAttribute("the_geom");
//////					if (geom.intersects(geom1))
////                    if (geom.getGeometryN(0).getCoordinates()[0].distance(geom1.getCoordinate()) <= 0.000001) {
////
////                        StringWriter writer2 = new StringWriter();
////                        FeatureJSON fjson1 = new FeatureJSON();
////                        fjson1.writeFeature(feature2, writer2);
////                        String sjson2 = writer2.toString();
////                        JSONObject object2 = JSONObject.fromObject(sjson2);
////                        JSONObject properties2 = object2.getJSONObject("properties");
////                        startGeometries.add(properties2);
////
////                    }
////                    if (geom.getGeometryN(0).getCoordinates()[1].distance(geom1.getCoordinate()) <= 0.000001) {
////
////                        StringWriter writer2 = new StringWriter();
////                        FeatureJSON fjson1 = new FeatureJSON();
////                        fjson1.writeFeature(feature2, writer2);
////                        String sjson2 = writer2.toString();
////                        JSONObject object2 = JSONObject.fromObject(sjson2);
////                        JSONObject properties2 = object2.getJSONObject("properties");
////                        endGeometries.add(properties2);
////
////                    }
////
////                }
//                JSONObject startFeature = new JSONObject();
//                JSONObject endFeature = new JSONObject();
//
//                for (int i = 0; i < startGeometries.size(); i++) {
//                    for (int j = 0; j < endGeometries.size(); j++) {
//                        Double startNum = Double.parseDouble(startGeometries.get(i).get("序号").toString());
//                        Double endNum = Double.parseDouble(endGeometries.get(j).get("序号").toString());
//
//                        if (Math.abs(startNum - endNum) <= 1) {
//                            startFeature = startGeometries.get(i);
//                            endFeature = endGeometries.get(j);
//                        }
//
//                    }
//
//                }
//                if (properties.getString("OBJECTID").equals("495")) {
//                    System.out.println();
//                }
//                if (startGeometries.size() == 0 && endGeometries.size() > 0) {
//                    startFeature = endGeometries.get(0);
//                    endFeature = endGeometries.get(0);
//                }
//                if (startGeometries.size() > 0 && endGeometries.size() == 0) {
//                    startFeature = startGeometries.get(0);
//                    endFeature = startGeometries.get(0);
//                }
//
////				Dist dist = new Dist();
////				dist.setCity(properties.getString("shi"));
////				dist.setCode(properties.getString("XZQDM"));
////				dist.setCountry(properties.getString("XZQMC"));
////				dist.setCounty(properties.getString("xian"));
////				dist.setCreatedate(new Date());
////				dist.setProvince("辽宁省");
////				dist.setShape(geoString);
////				dist.setTown(properties.getString("zhen1"));
//
//                // System.out.println(geoString);
////Geometry geom = (Geometry) feature.getAttribute("the_geom");//
//                // System.out.println(object);
//
//                tb.add("the_geom", MultiLineString.class);
//                SimpleFeature featureNew = featureWriter.next();
//                featureNew.setAttribute("OBJECTID", properties.getString("OBJECTID"));
//                featureNew.setAttribute("LineWt", properties.getString("LineWt"));
//                featureNew.setAttribute("Layer", properties.getString("Layer"));
//                featureNew.setAttribute("高", properties.getString("Elevation"));
//
//                featureNew.setAttribute("StartH", startFeature.getString("地面标高"));
//                featureNew.setAttribute("EndH", endFeature.getString("地面标高"));
//                featureNew.setAttribute("StartDepth", startFeature.getString("埋深（m）"));
//                featureNew.setAttribute("EndDepth", endFeature.getString("埋深（m）"));
//                Pattern pattern = Pattern.compile("[^0-9]");
//                Matcher matcher = pattern.matcher(startFeature.getString("管径或管件"));
//                String all = matcher.replaceAll("");
//                featureNew.setAttribute("Calibre", all);
//                featureNew.setAttribute("Type", "圆管");
//                featureNew.setAttribute("ProName", startFeature.getString("项目名称"));
//                featureNew.setAttribute("Property", startFeature.getString("管道属性"));
//                featureNew.setAttribute("PressureL", startFeature.getString("压力级制"));
//                featureNew.setAttribute("StartPoint", startFeature.getString("点编号"));
//                featureNew.setAttribute("EndPoint", endFeature.getString("点编号"));
//
//                featureNew.setAttribute("the_geom", geom);
//
//
//            }
//            featureWriter.write();
//            featureWriter.close();
//            ds.dispose();
//            System.out.println(cout);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//
//    static List<SummaryTable> readXls2Entity(SimpleFeatureType type, File file) throws Exception {
//        //A list to collect result as we create them.
//        List<SimpleFeature> result = new ArrayList<>();
//
//        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
//        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
//
//        ExcelReader reader = new ExcelReader(file);
//
//        List<List<String>> read = reader.read(0);
//        List<SummaryTable> summaryTableList = GenericShp2.listStringConvert2Entity(read, SummaryTable.class);
//
//        return summaryTableList;
//    }
//
//}
